<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>JavaScript 数组 </title>
</head>
<body>
<h2>添加数组元素 push()</h2>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>

<script>
  var fruits=["Banana", "Orange", "Apple", "Mango"];
  document.getElementById("demo").innerHTML=fruits;

  function myFunction(){
    fruits.push("Lemon");  //fruits[fruits.length] = "Lemon"; 也可以使用 length 属性向数组添加新元素
    document.getElementById("demo").innerHTML=fruits;
  }
</script>
</body>
</html>